package com.fanhang.samples.spring.security.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

import com.fanhang.samples.spring.security.dao.UserDao;
import com.fanhang.samples.spring.security.po.User;

/**
 * 用户
 */
@Repository
public class UserDaoImpl implements UserDao {

	@Override
	public User get(String userName) {
		Assert.hasText(userName, "用户名不能为空");
		
		List<String[]> userList = User.userList;
		/*
		 * 从[userList]中按用户名搜索用户
		 */
		String[] userRow = null;
		for (String[] row : userList) {
			if (userName.equals(row[1])) {
				userRow = row;
			}
		}
		if (userRow == null) {
			return null;
		}
		User user = new User();
		user.setId(Long.valueOf(userRow[0]));
		user.setUserName(userRow[1]);
		user.setPassword(userRow[2]);
		user.setRoleString(userRow[3]);
		return user;
	}
	
}
